package  
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.*;
	import flash.xml.XMLDocument;
	/**
	 * ...
	 * @author Joseph Waters
	 */
	public class DBMessaging extends EventDispatcher
	{
		public var dataReturned:String = new String();
		public var xml:XML = new XML();
		public var xmlList:XMLList;
		
		private var curDate:Date = new Date();
		
		public function DBMessaging() 
		{
			super(null);
		}
		
		private function testDataSend(dataToSend:String):void {
			curDate = new Date();
			var timeStamp:String = String(curDate.getHours()) + String(curDate.getMinutes()) + String(curDate.getSeconds());
			timeStamp = timeStamp + String(curDate.getFullYear()) + String(curDate.getMonth()) + String(curDate.getDate());
			dataToSend = "newId=1&newInfo=" + dataToSend + "&newTime=" + timeStamp;
			sendData(dataToSend);
		}
		
		public function sendData(dataToSend:String):void {
			var loader : URLLoader = new URLLoader;
			var urlreq:URLRequest = new URLRequest("http://www.watersArtistry.com/game01/uniCon.php");
			var urlvars: URLVariables = new URLVariables;
			loader.dataFormat = URLLoaderDataFormat.TEXT;
			urlreq.method = URLRequestMethod.POST;
			urlvars.decode("functionType=push&" + dataToSend);
			urlreq.data = urlvars;
			loader.addEventListener(Event.COMPLETE, loadCompleted);
			loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			loader.load(urlreq);
		}
		
		public function getData():void {
			var loader: URLLoader = new URLLoader;
			var urlreq:URLRequest = new URLRequest("http://www.watersArtistry.com/game01/uniCon.php");
			var urlvars: URLVariables = new URLVariables;
			loader.dataFormat = URLLoaderDataFormat.TEXT;
			urlreq.method = URLRequestMethod.POST;
			urlvars.decode("functionType=pull");
			urlreq.data = urlvars;
			loader.addEventListener(Event.COMPLETE, loadCompleted);
			loader.load(urlreq);
		}
				
		private function loadCompleted(event:Event):void
		{
			var loader2:URLLoader = URLLoader(event.target);
			dataReturned = event.target.data;
			
			var evt:Event = new Event(Event.COMPLETE);
			dispatchEvent(evt);
		}
		
		private function onIOError(ioE:IOErrorEvent):void {
			trace("URL Could not be loaded.");
		}
		
		private function pullCompleted(event:Event):void
		{
			var loader2:URLLoader = URLLoader(event.target);
		}	
	}

}